package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.com.qiancheng.dto.Answer;
import cn.com.qiancheng.util.DbUtil;

public class AnswerDao {
	public List<Answer> searchAnswer(int id) {
		List<Answer> list = new ArrayList<>();
		Answer answer = null;
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT a_id,a_q_id,a_content,a_order FROM t_answer WHERE t_answer.a_q_id = ?";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setInt(1, id);
			ResultSet rs = stat.executeQuery();
			while (rs.next()) {
				answer = new Answer();
				answer.setA_id(Integer.parseInt(rs.getString("a_id")));
				answer.setQ_id(Integer.parseInt(rs.getString("a_q_id")));
				answer.setContent(rs.getString("a_content"));
				answer.setOrder("a_order");
				list.add(answer);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}
}
